package com.lishe.lishe.lishe.module.myorder.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lishe.lishe.R;
import com.lishe.lishe.lishe.MyRecyclerView.TimeLineDecoration;
import com.lishe.lishe.lishe.base.BaseActivity;
import com.lishe.lishe.lishe.module.excitation.adapter.TimePathAdapter;
import com.lishe.lishe.lishe.module.myorder.adapter.CourierAdapter;
import com.lishe.lishe.lishe.module.myorder.bean.CourierObject;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by yang on 2018/1/31.
 * <p>
 * 快递信息
 */

public class CourierActivity extends BaseActivity {

    public static void jump(Activity activity, ArrayList<CourierObject> cours) {
        Intent intent = new Intent(activity, CourierActivity.class);
        intent.putExtra("cours", cours);
        activity.startActivity(intent);
    }

    private SmartRefreshLayout mSmartLayout;
    private RecyclerView mRecyclerView;
    private Button mButtonBack;
    private TextView mTextTitle,mTextEmpty;
    private RelativeLayout mRelativeEmpty;


    private ArrayList<CourierObject> mList;
    private CourierAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_logistics);

        initView();
        setListener();
        setAdapter();
        setSmartLayout();
    }

    private void initView() {
        mButtonBack = findViewById(R.id.title_left_button);
        mTextTitle = findViewById(R.id.title_text_title);
        mSmartLayout = findViewById(R.id.refreshlayout);
        mRecyclerView = findViewById(R.id.listView);
        mTextEmpty = findViewById(R.id.empty_text);
        mRelativeEmpty = findViewById(R.id.empty);

        mTextTitle.setText("快递信息");
        mTextEmpty.setText("暂无快递信息哦~");
        mRecyclerView.setBackgroundColor(getResources().getColor(R.color.white));
    }

    private void setListener() {
        mButtonBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void setAdapter() {
        mList = getIntent().getParcelableArrayListExtra("cours");
        if(mList==null||mList.size()==0){
            mRelativeEmpty.setVisibility(View.VISIBLE);
        }else {
            mRelativeEmpty.setVisibility(View.GONE);

            adapter = new CourierAdapter(mList);

            mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
            TimeLineDecoration mItemDecoration = new TimeLineDecoration
                    .Builder(this)
                    .setItemStyle(TimeLineDecoration.STYLE_RESOURCE)//选择dot使用图片资源或者用canvas画
                    .setTopDistance(20)//单位dp
                    .setItemInterVal(10)//单位dp
//                .setItemPaddingLeft(10)//如果不设置，默认和item间距一样
//                .setItemPaddingRight(10)//如果不设置，默认和item间距一样
                    .setDotRadius(4)//单位dp小圆半径
//                .setDotColor(R.color.line_da)
//                .setDotPaddingTop(0)
//                .setDotInItemOrientationCenter(false)//设置dot居中
//                .setLineColor(R.color.line_da)//设置线的颜色
                    .setLineWidth(1)//单位dp
                    .setEndText("END")//设置结束的文字
                    .setTextColor(Color.WHITE)
                    .setTextSize(10)//单位sp
//                .setDotPaddingText(2)//单位dp.设置最后一个点和文字之间的距离
//                .setBottomDistance(0)//设置底部距离，可以延长底部线的长度
//                .setDotPaddingTop(4)
                    .setCicleImageResourse(R.mipmap.time_line_point, 0)
                    .create();
            mRecyclerView.addItemDecoration(mItemDecoration);
            mRecyclerView.setAdapter(adapter);
        }
    }

    private void setSmartLayout() {
        mSmartLayout.setEnableLoadmore(false);
        mSmartLayout.setEnableRefresh(false);
    }
}
